/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 * Version：V1.0.2(20230701).
 */
package top.hiai.search;

import com.jfinal.plugin.activerecord.Page;
import top.hiai.common.model.Article;

import java.util.List;

/**
 * @Author www.hiai.top
 * @Email goodsking@163.com
 * @Message 更多资源尽在www.hiai.top
 * @Introduction 类的介绍
 */

public class SearchService {

    public static final SearchService me = new SearchService();

    private Article articleDao = new Article().dao();

    /**
     * 文章搜索
     */
    public List<Article> articleSearch(String q) {
        return articleDao.find("select * from bbs_article where status=1 and concat(ifnull(`title`,''),ifnull(`content`,'')) like '%" + q + "%'");
    }

    /**
     * 文章搜索分页显示
     */
    public Page<Article> articleSearchPaginate(int pageNumber, int pageSize, String q) {
//        String from = " select a.aid,a.uid,a.title,a.replyCount,a.favoriteCount,u.avatar,u.nickName,u.is_auth ";
//        String select = " from bbs_article a,bbs_user u where a.uid=u.uid and a.status=1 and a.is_del=0 and concat(ifnull(`a.title`,''),ifnull(`a.content`,'')) like '%" + q + "%' ";
//        Page<Article> articlePage = articleDao.paginate(pageNumber, pageSize, from, select);
//        return articlePage;

        String from = " select a.aid,a.title,a.replyCount,a.favoriteCount ,u.avatar,u.nickName,u.is_auth";
        String select = " from bbs_article as a,bbs_user as u where a.uid=u.uid and a.status=1 and a.is_del=0 and concat(ifnull(`title`,''),ifnull(`content`,'')) like '%" + q + "%' ";
        Page<Article> articlePage = articleDao.paginate(pageNumber, pageSize, from, select);
        return articlePage;
    }

}